﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NYForm
{
    public partial class Form1 : Form
    {
        static int sb;
        public WeightCalc.NY_Present gift;
        public ConsoleView.FileLogger f;
        public Form1()
        {
            f = new ConsoleView.FileLogger();
            gift = new WeightCalc.NY_Present();
            InitializeComponent();
            label2.Text = "";
            label3.Text = "Количество";
            label4.Text = "";
            label5.Text = "Вес";
            textBox1.Enabled = false;
            textBox2.Enabled = false;
            numericUpDown1.Enabled = false;
            numericUpDown2.Enabled = false;
        }
        //sweet
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            sb = 1;
            label2.Text = "Цвет";
            textBox1.Enabled = true;
            label4.Text = "Вкус";
            textBox2.Enabled = true;
            numericUpDown1.Enabled = true;

            numericUpDown2.Enabled = true;
        }
        //candy
        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            sb = 3;
            label2.Text = "Фирма";
            textBox1.Enabled = true;
            label4.Text = "Начинка";
            textBox2.Enabled = true;
            numericUpDown1.Enabled = true;
            numericUpDown2.Enabled = true;
        }
        //chocolate
        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            sb = 2;
            label2.Text = "Процент какао";
            textBox1.Enabled = true;
            textBox1.Text = "0,0";
            label4.Text = "";
            textBox2.Enabled = false;
            numericUpDown1.Enabled = true;
            numericUpDown2.Enabled = true;
        }
        //lol
        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            sb = 4;
            label2.Text = "Состав";
            textBox1.Enabled = true;
            label4.Text = "";
            textBox2.Enabled = false;
            numericUpDown1.Enabled = true;
            numericUpDown2.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch (sb)
            {
                case 1://Sweet

                    gift.setSweetSets(Convert.ToInt32(numericUpDown1.Value),
                                      Convert.ToDouble(numericUpDown2.Value),
                                      textBox1.Text.ToString(),
                                      textBox2.Text.ToString());
                    break;
                case 2://Chocolade

                    gift.setChocoladeSets(Convert.ToInt32(numericUpDown1.Value),
                                          Convert.ToDouble(numericUpDown2.Value),
                                          Convert.ToDouble(textBox1.Text.ToString()));
                   
                     break;
                case 3://Candy
                    gift.setCandySets(Convert.ToInt32(numericUpDown1.Value), 
                                      Convert.ToDouble(numericUpDown2.Value),
                                      textBox1.Text.ToString(),
                                      textBox2.Text.ToString());
                    break;
                case 4://lollipop
                    gift.setLollipopsSets(Convert.ToInt32(numericUpDown1.Value), 
                                          Convert.ToDouble(numericUpDown2.Value),
                                          textBox1.Text.ToString());
                    break;
                default:
                    toolStripStatusLabel1.Text = "error";
                    break;
            }
            toolStripStatusLabel1.Text = "Общий вес: "+gift.getWeight().ToString();
            f.Log(gift);


        }

        private void button2_Click(object sender, EventArgs e)
        {

            treeView1.BeginUpdate();
            treeView1.Nodes.Clear();
            treeView1.Nodes.Add("Candy");
            int i = 0;
            gift.candy.ForEach(delegate(NYdlls.Candy c)
            {
                treeView1.Nodes[0].Nodes.Add(i.ToString());
                treeView1.Nodes[0].Nodes[i].Nodes.Add("Начинка " + c.getFilling());
                treeView1.Nodes[0].Nodes[i].Nodes.Add("Фирма " + c.getFirm());
                treeView1.Nodes[0].Nodes[i].Nodes.Add("Вес " + c.getWeight().ToString());
                i++;
            });
            i = 0;
            treeView1.Nodes.Add("Lollipop");
            gift.lol.ForEach(delegate(NYdlls.Lollipop c)
            {
                treeView1.Nodes[1].Nodes.Add(i.ToString());
                treeView1.Nodes[1].Nodes[i].Nodes.Add("Состав " + c.getConsist());
                treeView1.Nodes[1].Nodes[i].Nodes.Add("Вес " + c.getWeight().ToString());
                i++;
            });
            i = 0;
            treeView1.Nodes.Add("Chocolate");
            gift.choco.ForEach(delegate(NYdlls.Chocolate c)
            {
                treeView1.Nodes[2].Nodes.Add(i.ToString());
                treeView1.Nodes[2].Nodes[i].Nodes.Add("Процент какао " + c.getPercent().ToString());
                treeView1.Nodes[2].Nodes[i].Nodes.Add("Вес " + c.getWeight().ToString());
                i++;
            }); 
            i = 0;
            treeView1.Nodes.Add("Sweet");
            gift.sweet.ForEach(delegate(NYdlls.Sweet c)
            {
                treeView1.Nodes[3].Nodes.Add(i.ToString());
                treeView1.Nodes[3].Nodes[i].Nodes.Add("Вкус "+c.getTaste().ToString());
                treeView1.Nodes[3].Nodes[i].Nodes.Add("Цвет " + c.getColor().ToString());
                treeView1.Nodes[3].Nodes[i].Nodes.Add("Вес " + c.getWeight().ToString());
                i++;
            });
            treeView1.EndUpdate();
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {
            
        }
    }
}
